from sqlalchemy import Column, Integer, String, JSON, Identity, ForeignKey
from sqlalchemy.orm import relationship
from app.database import Base

class MortarTest(Base):
    __tablename__ = "mortar_test"

    id = Column(Integer, Identity(), primary_key=True)
    source = Column(String(50), nullable=False)
    uuid = Column(String(50), nullable=False)
    precative_num = Column(String(50), nullable=False)
    equ_num = Column(String(50), nullable=False)
    trial_date = Column(String(50), nullable=False)
    produce_date = Column(String(50), nullable=False)
    precative_date = Column(String(50), nullable=False)
    report_num = Column(String(50), nullable=False)
    bridge_name = Column(String(200), nullable=False)
    other_location = Column(String(200))
    streng_grade = Column(String(50), nullable=False)
    kind = Column(String(50), nullable=False)  # 水泥品种
    curing_age = Column(String(50), nullable=False)
    result = Column(String(10), nullable=False)  # 总试验结果
    result1 = Column(String(10), nullable=False)  # 抗压试验结果
    result2 = Column(String(10), nullable=False)  # 抗折试验结果
    typical_value = Column(String(50), nullable=False)  # 抗压代表值
    typical_value2 = Column(String(50), nullable=False)  # 抗折代表值
    
    # 关联子表数据
    data_list = relationship("MortarData", back_populates="parent")

class MortarData(Base):
    __tablename__ = "mortar_data"

    id = Column(Integer, Identity(), primary_key=True)
    uuid = Column(String(50), nullable=False)
    sample_id = Column(Integer, nullable=False)
    kyhz1 = Column(String(50), nullable=False)  # 抗压荷载1
    kyqd1 = Column(String(50))  # 抗压强度1
    cruveky1 = Column(String(1000))  # 抗压力值曲线1
    kyhz2 = Column(String(50), nullable=False)  # 抗压荷载2
    kyqd2 = Column(String(50))  # 抗压强度2
    cruveky2 = Column(String(1000))  # 抗压力值曲线2
    kzhz = Column(String(50), nullable=False)  # 抗折荷载
    kzqd = Column(String(50))  # 抗折强度
    cruvekz = Column(String(1000))  # 抗折力值曲线
    parent_id = Column(String(50), nullable=False)
    test_id = Column(Integer, ForeignKey('mortar_test.id'))
    
    # 关联父表
    parent = relationship("MortarTest", back_populates="data_list") 